package com.buyantech.smweb.dao;

import java.util.List;

import javacommon.base.BaseHibernateDao;

import org.springframework.stereotype.Repository;
import cn.org.rapid_framework.page.Page;
import com.buyantech.smweb.model.User;
import com.buyantech.smweb.vo.query.UserQuery;

@Repository
public class UserDao extends BaseHibernateDao<User,java.lang.String>{

	@Override
	public Class getEntityClass() {
		return User.class;
	}
	
	public Page findPage(UserQuery query) {
		String sql = "select t from User t where 1=1 "
				+ "/~ and t.id = {id} ~/"
			  	+ "/~ and t.username = {username} ~/"
			  	+ "/~ and t.ratio = {ratio} ~/"
			 	+ "/~ and t.userid = {userid} ~/"
			 	+ "/~ and t.paterid = {paterid} ~/"
				+ "/~ order by [sortColumns] ~/";
		return pageQuery(sql,query);
	}

	public Page searchPage(UserQuery query) {
		String sql = "select t from User t where 1=1 "
			  	+ "/~ and t.id like '%[id]%' ~/"
			  	+ "/~ and t.userid like '%[userid]%' ~/"
				+ "/~ and t.username = '%[username]%' ~/";
			  	if(query.getState()!=0){
			  		sql+="/~ and t.state like '%[state]%' ~/";			  		
			  	}
			  	sql+= "/~ and t.qq like '%[qq]%' ~/"
			  	+ "/~ and t.phone like '%[phone]%' ~/"
			  	+ "/~ and t.zfb like '%[zfb]%' ~/"
			  	+ "/~ and t.cft like '%[cft]%' ~/"
				+ "/~ and t.paterDate  >=  {paterdatebegin} ~/"
			  	+ "/~ and t.paterDate <= {paterdateend} ~/"
			  	+ "/~ and t.register  >=  {registerbegin} ~/"
			  	+ "/~ and t.register <= {registerend} ~/"
			  	+ "/~ and t.paterid like '%[paterid]%' ~/"
			  	+ "/~ and t.paterDate like '%[PaterDate]%' ~/"
				+ "/~ and t.IP like '%[IP]%' ~/"
				+ "/~ order by [sortColumns] ~/";
        //生成sql2的原因是为了不喜欢使用xsqlbuilder的同学，请修改生成器模板，删除本段的生成
		return pageQuery(sql,query);
	}
	
	public Page searchPage1(UserQuery query) {
		String sql = "select t from User t where 1=1 "
			  	+ "/~ and t.id like '%[id]%' ~/"
			  	+ "/~ and t.userid like '%[userid]%' ~/"
				+ "/~ and t.username = '%[username]%' ~/";
			  	if(query.getState()!=0){
			  		sql+="/~ and t.state like '%[state]%' ~/";			  		
			  	}
			  	sql+= "/~ and t.qq like '%[qq]%' ~/"
			  	+ "/~ and t.phone like '%[phone]%' ~/"
			  	+ "/~ and t.zfb like '%[zfb]%' ~/"
			  	+ "/~ and t.cft like '%[cft]%' ~/"
			  	+ "/~ and t.register  >=  {registerbegin} ~/"
			  	+ "/~ and t.register <= {registerend} ~/"
			  	+ "/~ and t.paterid like '%[paterid]%' ~/"
			  	+ "/~ and t.paterDate like '%[PaterDate]%' ~/"
				+ "/~ and t.IP like '%[IP]%' ~/"
			  	+" and isvip=1 "
				+ "/~ order by [sortColumns] ~/";
        //生成sql2的原因是为了不喜欢使用xsqlbuilder的同学，请修改生成器模板，删除本段的生成
		return pageQuery(sql,query);
	}
	public List<User> findByUsernameOrPwd(String username,String pwd){
		return getHibernateTemplate().find("from User u where u.username=? and u.passwrod=?",username,pwd);
	}
 
}
